import cv2
import numpy as np

img = cv2.imread('1.jpg', cv2.IMREAD_GRAYSCALE)
ret,thresh1 = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
cv2.imshow('img',img)
cv2.imshow('thresh1',thresh1)
kernel = np.ones((3,3), np.uint8)
erosion = cv2.erode(thresh1, kernel, iterations=1)
dilate = cv2.dilate(erosion, kernel, iterations=1)
cv2.imshow('erosion',erosion)
cv2.imshow('dilate',dilate)
cv2.waitKey(0)
cv2.destroyAllWindows()